from typing import List

# 因当前[1,1],[1,1] 测试用例错误，尚未提交
class Solution:
    def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
        return self.findMedian(self.merge(nums1, nums2))

    def merge(self, nums1: List[int], nums2: List[int]):
        nums = nums1 + nums2
        i = len(nums1)
        while(i < len(nums)):
            j = i - 1
            while(nums[j] > nums[i] and j >= 0):
                nums[j], nums[i] = nums[i], nums[j]
                j -= 1
            i += 1
        return nums

    def findMedian(self, nums: List[int]):
        size = len(nums)
        if size % 2 == 0:
            return (nums[size//2 - 1] + nums[size//2]) / 2
        else:
            return nums[size//2]


if __name__ == "__main__":
    nums1 = [1, 3]
    nums2 = [2]
    print(Solution().findMedianSortedArrays(nums1, nums2))

    nums1 = [1, 2]
    nums2 = [3, 4]
    print(Solution().findMedianSortedArrays(nums1, nums2))

    nums1 = [1, 1]
    nums2 = [1,1]
    print(Solution().findMedianSortedArrays(nums1, nums2))
